package emoji

import (
	"fmt"
	"strconv"
	"unicode/utf16"
)

//表情转换
func UnicodeEmojiCode(s string) string {
	ret := ""
	rs := []rune(s)
	for i := 0; i < len(rs); i++ {
		if len(string(rs[i])) == 4 {
			u := `[\u` + strconv.FormatInt(int64(rs[i]), 16) + `]`
			ret += u

		} else {
			ret += string(rs[i])
		}
	}
	return ret
}

// EmojiEncode Emoji表情转码
func EmojiEncode(s string) string {
	ret := ""
	rs := []rune(s)
	for i := 0; i < len(rs); i++ {
		if len(string(rs[i])) == 4 {
			r1, r2 := utf16.EncodeRune(rs[i])
			t1 := "\\u" + fmt.Sprintf("%x", r1)
			t2 := "\\u" + fmt.Sprintf("%x", r2)
			ret += t1 + t2
		} else {
			ret += string(rs[i])
		}
	}
	return ret
}
